<template>
  <el-dialog
      title="意见反馈"
      :width="450"
      :show-close="false"
      :close-on-click-modal="false"
      center>
    <el-form :model="this.feedBack" :rules="feedBackRules" ref="feedBackRules">
      <el-select
          v-model="this.feedBack.accountNo"
          filterable
          placeholder="请选择老师"
          class="add-nation-input"
      >
        <el-option
            v-for="key in this.allTeacher"
            :key="key.accountNo"
            :label="key.name"
            :value="key.accountNo"
        ></el-option>
      </el-select>
      <el-form-item label="反馈内容" prop="content">
        <el-input
            v-model="this.feedBack.content"
            style="width: 440px"
            :rows="5"
            type="textarea"
            placeholder="请输入反馈内容，可以包括但不限于系统功能、学院教师等"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="cancelClick('feedBackRules')">取消</el-button>
      <el-button type="primary" @click="confirmFeedback('feedBackRules')">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import request from "@/util/request.js";
import {ElMessage} from "element-plus";

export default {
  name: "oneTeacherRelated",
  data() {
    return {
      feedBack: {},
      allTeacher:[],
      feedBackRules: {
        content: [
          {required: true, message: '请输入反馈内容', trigger: 'blur'}
        ],
        accountNo:[
          {required: true, message: '请选择奖项类型', trigger: 'blur'}
        ]
      },
    }
  },
  created() {
    this.getAllTeacher()
  },
  methods: {
    cancelClick(feedBackRules) {
      this.$store.commit('oneTeacherDialogShow')
      this.$refs[feedBackRules].resetFields();
      this.feedBack = {}
    },
    confirmFeedback() {
      this.$refs.feedBackRules.validate((valid) => {
        if (valid) {
          this.feedBack.type = "2"
          this.feedBack.studentAccountNo= JSON.parse(localStorage.getItem('user')).accountNo,
          this.$confirm(' 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'info'
          }).then(() => {
            this.$store.commit('oneTeacherDialogShow')
            request.post("/related_feedback/edit", this.feedBack).then(res => {
              if (res.data.data) {
                this.feedBack = {}
                ElMessage({
                  type: 'success',
                  message: '成功提交，感谢反馈!'
                });
              }
            })
          })
        } else {
          ElMessage({
            type: 'warning',
            message: "请输入内容"
          });
        }
      });
    },
    getAllTeacher(){
      if (typeof(JSON.parse(localStorage.getItem('user')).classNo) !== "undefined")
      request.get("/info_account/oneGetAllTeacher?classNo=" + JSON.parse(localStorage.getItem('user')).classNo).then(res =>{
        this.allTeacher = res.data.data
      })
    }
  }
}
</script>

<style scoped>
.dialog-footer {
  text-align: center;
}
</style>
